package interaction.game;

import java.util.Iterator;
import java.util.LinkedList;

import processing.core.PGraphics;

public class GameObjectCollection extends LinkedList<GameObject> implements GameObject {
	
	private boolean iterateInDescendingOrder = false;
	
	public void update()
	{
		iterateInDescendingOrder = true;
		for (GameObject o : this) {
			o.update();
		}
	}
	
	public void draw(PGraphics g) {
		iterateInDescendingOrder = false;
		for (GameObject o : this) {
			o.draw(g);
		}
	}
	
	public Iterator<GameObject> iterator() {
		if (iterateInDescendingOrder) {
			return descendingIterator();
		}
		return super.iterator();
	}

}
